<template>
  <div>
    <el-card>
      <h1>用户管理</h1>
      <el-button type="primary" @click="dialogVisible = true" size="mini"
        >添加用户</el-button
      >
      <!-- 表格区域 -->
      <el-table :data="tableData.rows" stripe style="width: 100%">
        <el-table-column prop="username" label="用户名"> </el-table-column>
        <el-table-column label="性别" show-overflow-tooltip>
          <template slot-scope="{ row }">
            {{ row.sex || "暂无数据" }}
          </template>
        </el-table-column>
        <el-table-column label="角色" show-overflow-tooltip>
          <template slot-scope="{ row }">
            {{ row.rolename || "暂无数据" }}
          </template>
        </el-table-column>
        <el-table-column label="邮箱" show-overflow-tooltip>
          <template slot-scope="{ row }">
            {{ row.mail || "暂无数据" }}
          </template>
        </el-table-column>
        <el-table-column label="手机号" show-overflow-tooltip>
          <template slot-scope="{ row }">
            {{ row.phone || "暂无数据" }}
          </template>
        </el-table-column>
        <el-table-column label="创建者" show-overflow-tooltip>
          <template slot-scope="{ row }">
            {{ row.creator || "暂无数据" }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150">
          <el-button type="primary" size="mini">编辑</el-button>
          <el-button type="danger" size="mini">删除</el-button>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.count"
      >
      </el-pagination>
    </el-card>
    <!-- 弹出框区域 -->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="活动名称">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="createUser()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { request } from "../../api/request";
export default {
  data() {
    return {
      page: { pageNum: 1, pageSize: 5 }, // 分页数据
      tableData: [], // 用户列表数据
      currentPage4: 1, // 默认页码
      dialogVisible: false, // 弹出框默认false
      form: {}, // form 表单对象
    };
  },
  created() {
    this.getUserList();
  },
  methods: {
    // 对话框关闭
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
        })
        .catch(() => {});
    },
    // 添加用户
    createUser() {
      this.dialogVisible = false;
    },
    // 获取用户列表
    getUserList() {
      request({
        query:this.page,
        method: "GET",
        url: "user",
        route: "list",
      }).then((res) => {
        this.tableData = res.data;
      });
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      request({
        ...this.page,
        method: "GET",
        url: "user",
        route: "list",
      });
    },
    handleCurrentChange(val) {
      this.page.pageNum = val;
      request({
        ...this.page,
        method: "GET",
        url: "user",
        route: "getList",
      });
    },
  },
};
</script>
<style lang="less" scoped>
.el-pagination {
  margin-top: 20px;
}
// .el-card{
//   transition: 1s;
// }
// .el-main{
//   div{
//     // opacity: 0;
//   }
// }

</style>